#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 即将拥有人鱼线的yjw
   @Time: 2024/4/17 17:15
   @File: clientInfoTa.py
   @desc:
"""
from random import choice

from DataTest.tabledata.commonData import randomInfo
from DataTest.tabledata.commonData.SQLMontage import get_sql_key, get_sql
from DataTest.tabledata.commonData.clientInfo import c_businflag_list
from DataTest.tabledata.dataTest import fake


def client_info_hsraw_ta(TAACCOUNTID,init_date,c_tano='ZX'):
    client_list = {}
    client_list.update(randomInfo.generate_info_raw_ta())
    #hsraw层，TA接口
    # TAACCOUNTID = str(randomInfo.get_random_number(12)) #基金账户
    c_custtype = '1'
    c_identitytype = '0'
    c_accostatus = 'N'
    c_requestno = TAACCOUNTID + str(randomInfo.get_random_number(8))
    c_outbusinflag = '101'
    ADDRESS = randomInfo.get_address().split(' ')[0] #通讯地址
    addr_zip = randomInfo.get_address().split(' ')
    POSTCODE = addr_zip[1]  #邮政编码
    TRD_ACCT = TAACCOUNTID + str(randomInfo.get_random_number(8)) # 交易账户
    bankinfo = randomInfo.get_bank().split(' ')
    INVESTOR_BANK_NAME = bankinfo[0]  # 开户银行名称
    c_bankno = bankinfo[1]  # 开户银行简称
    INVESTOR_BANK_ACCT = '622' + str(randomInfo.get_random_number(12))  # 银行卡号
    d_requestdate =  randomInfo.get_random_date(20230102,20240717) #申请日期
    d_cdate = d_requestdate
    d_date = d_requestdate
    d_regdate = d_requestdate
    agencyinfo = randomInfo.get_agency().split(' ')
    DISTRIBUTORCODE = agencyinfo[0] #销售商编号
    c_agencyname = agencyinfo[1]#销售商名称
    c_agencytype = agencyinfo[2]#销售商类型
    annualincome = randomInfo.get_random_number(6)
    livingcountry = '156'
    nationality = '156'
    certvaliddate = randomInfo.get_random_date(20240102,20401228)
    # client_list.update({'Bankcode': c_bankno})
    netcode = str(randomInfo.get_random_number(6))
    client_list.update({'netcode':netcode})
    client_list.update({'netname': f'网点{netcode}'})
    client_list.update({'agencycode': DISTRIBUTORCODE})
    client_list.update({'transactionaccountid': TRD_ACCT})
    client_list.update({'taserialno': TRD_ACCT})
    client_list.update({'Transactionaccountnumber': TRD_ACCT})
    client_list.update({'fundaccountnumber': TAACCOUNTID})
    client_list.update({'nationality': nationality})
    client_list.update({'certvaliddate':certvaliddate})
    client_list.update({'livingcountry':livingcountry})
    client_list.update({'annualincome':annualincome})
    client_list.update({'TAACCOUNTID':TAACCOUNTID})
    client_list.update({'c_custtype':c_custtype})
    client_list.update({'c_identitytype':c_identitytype})
    client_list.update({'c_accostatus':c_accostatus})
    client_list.update({'c_requestno':c_requestno})
    client_list.update({'c_outbusinflag':c_outbusinflag})
    client_list.update({'ADDRESS':ADDRESS})
    client_list.update({'POSTCODE':POSTCODE})
    client_list.update({'TRD_ACCT':TRD_ACCT})
    client_list.update({'INVESTOR_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'OPEN_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'c_bankno':c_bankno})
    client_list.update({'INVESTOR_BANK_ACCT': INVESTOR_BANK_ACCT})
    client_list.update({'d_requestdate':d_requestdate})
    client_list.update({'d_cdate':d_cdate})
    client_list.update({'d_date':d_date})
    client_list.update({'d_regdate':d_regdate})
    client_list.update({'DISTRIBUTORCODE':DISTRIBUTORCODE})
    client_list.update({'c_agencyname':c_agencyname})
    client_list.update({'c_agencytype':c_agencytype})
    # print(client_list)

    # client_list = {}
    # client_list.update(randomInfo.generate_info_raw())
    #hsraw层，BTA接口
    c_status = choice(['0','1','8','9']) #产品状态
    c_requestno = 'sq'+str(randomInfo.get_random_number(8))+str(randomInfo.get_random_number(8))
    c_outbusinflag = choice(['101','103'])
    c_sharetype = choice(['A','B'])
    c_othershare = c_sharetype
    c_businflag = choice(c_businflag_list)
    c_moneytype = '156'
    c_udid = str(randomInfo.get_random_number(24))#通用唯一识别码
    bankinfo = randomInfo.get_bank().split(' ')
    INVESTOR_BANK_NAME = bankinfo[0]  #开户银行名称
    c_bankno = bankinfo[1]  #开户银行简称
    INVESTOR_BANK_ACCT = '622' + str(randomInfo.get_random_number(12))  #银行卡号
    INVESTOR_BANK_OPENADDR = bankinfo[1]   #开户行地址
    # d_requestdate =  randomInfo.get_random_date(20230102,20240717) #申请日期
    d_requestdate = init_date
    d_cdate = d_requestdate
    d_date = d_requestdate
    d_regdate = d_requestdate
    d_datadate = d_requestdate
    c_cserialno = str(randomInfo.get_random_number(8))+str(randomInfo.get_random_number(8))
    f_balance = randomInfo.get_random_number(6)
    f_confirmbalance = f_balance
    f_netvalue = 1.25
    f_confirmshares = f_confirmbalance / f_netvalue
    c_bonustype = '1'
    agencyinfo = randomInfo.get_agency_ta().split(' ')
    DISTRIBUTORCODE = agencyinfo[0] #销售商编号
    BRANCHCODE = DISTRIBUTORCODE
    c_agencyname = agencyinfo[1]#销售商名称
    c_agencytype = agencyinfo[2]#销售商类型
    proinfo = randomInfo.get_pro().split(' ')
    c_fundcode = proinfo[0] #产品编号
    c_fundname = proinfo[1]#产品名称
    c_property = proinfo[2]#产品性质
    Serialnumber = randomInfo.get_random_number(9)
    Universaluniqueidentifiedcode = fake.uuid4()[:-4]
    clientinfo = randomInfo.generate_info()
    transactor = f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|{clientinfo.get('cellphone_number')}|{clientinfo.get('email_address')}|#END#|" #经办人
    client_list.update({'transactor': transactor})
    client_list.update({'Universaluniqueidentifiedcode': Universaluniqueidentifiedcode})
    client_list.update({'Serialnumber': Serialnumber})
    client_list.update({'fundaccountnumber': TAACCOUNTID})
    client_list.update({'INVESTOR_BANK_OPENADDR':INVESTOR_BANK_OPENADDR})
    client_list.update({'BRANCHCODE':BRANCHCODE})
    client_list.update({'c_status':c_status})
    client_list.update({'c_requestno':c_requestno})
    client_list.update({'c_outbusinflag':c_outbusinflag})
    client_list.update({'c_sharetype':c_sharetype})
    client_list.update({'c_othershare':c_othershare})
    client_list.update({'c_businflag':c_businflag})
    client_list.update({'c_moneytype':c_moneytype})
    client_list.update({'c_udid':c_udid})
    client_list.update({'INVESTOR_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'INVESTOR_BANK_ACCT':INVESTOR_BANK_ACCT})
    client_list.update({'c_bankno': c_bankno})
    client_list.update({'d_requestdate':d_requestdate})
    client_list.update({'d_cdate':d_cdate})
    client_list.update({'d_date':d_date})
    client_list.update({'d_regdate':d_regdate})
    client_list.update({'d_datadate':d_datadate})
    client_list.update({'c_cserialno':c_cserialno})
    client_list.update({'f_balance':f_balance})
    client_list.update({'f_confirmbalance':f_confirmbalance})
    client_list.update({'f_netvalue':f_netvalue})
    client_list.update({'f_confirmshares':f_confirmshares})
    client_list.update({'c_bonustype':c_bonustype})
    client_list.update({'distributorcode':DISTRIBUTORCODE})
    client_list.update({'c_agencyname':c_agencyname})
    client_list.update({'c_agencytype':c_agencytype})
    client_list.update({'c_fundcode':c_fundcode})
    client_list.update({'c_fundname': c_fundname})
    client_list.update({'c_property': c_property})
    client_list.update({'FundCode':c_fundcode})
    defdividendmethod = choice(['0', '1'])
    client_list.update({'opbankofinvestorinclearing': INVESTOR_BANK_NAME})
    client_list.update({'acctnoofinvestorinclearing': INVESTOR_BANK_ACCT})
    client_list.update({'defdividendmethod': defdividendmethod})
    client_list.update({'c_tano': c_tano})
    # print(client_list)
    sql_list_copy= {k.lower(): v for k, v in client_list.items()}

    return sql_list_copy

def client_info_hsraw_ta_institution(TAACCOUNTID,init_date,c_tano='ZX'):
    client_list = {}
    #机构十五要素
    individualorinstitution = choice(['0','2',])   #机构标志
    investorname = fake.company()   #机构户名称
    accountabbr = investorname[:-4]  #机构简称
    certificatetype = choice(['0','1',])  #机构证件类型
    certificateno = randomInfo.random_credit_code()  #机构证件号码
    certificatevalidityperiod = randomInfo.get_random_date(20240402,20331228)  #证件有效期
    nationality ='156'  #国家和地区
    address = fake.address()  #联系地址
    telno = randomInfo.get_random_cell_phone() #联系电话
    emailaddress = randomInfo.get_random_email()  #邮箱
    transactionaccountid = TAACCOUNTID+'111'  #交易账号
    managerange = '经营范围'+ str(randomInfo.get_random_number(4))  #经营范围
    vocation =choice(['01','02','03','04','05','06','07','08','09','10','11','12']) #行业
    regcapital = randomInfo.get_random_number(8)   #注册资本
    currencytype = choice(['156','344','840']) #结算币种 156人民币  344港币 840 美元
    orgno = TAACCOUNTID +str(randomInfo.get_random_number(6)) #组织机构代码
    taxno = TAACCOUNTID +str(randomInfo.get_random_number(5)) #税务登记号
    clientinfo  = randomInfo.generate_info()
    instrepr = f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}| | "  #法定代表人
    clientinfo  = randomInfo.generate_info()
    transactor = f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|{clientinfo.get('cellphone_number')}|{clientinfo.get('email_address')}|#END#|" #经办人
    clientinfo  = randomInfo.generate_info()
    controlholder = f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|{clientinfo.get('cellphone_number')}|{clientinfo.get('email_address')}|#END#|" #控股股东
    clientinfo  = randomInfo.generate_info()
    actualcontroller =f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|{clientinfo.get('cellphone_number')}|{clientinfo.get('email_address')}|#END#|"  #实际控制人
    clientinfo  = randomInfo.generate_info()
    beneowner = f"{clientinfo.get('client_name')}|1|0|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|CN|浙江省杭州市西湖区|01|0.12345678|0|#END#|" #受益所有人
    if individualorinstitution == '2':
        investorprocode = str(randomInfo.get_random_number(6)) #投资者产品代码
        fundenddate = randomInfo.get_random_date(20240402,20331228)  #到期日
        clientinfo = randomInfo.generate_info()
        assetmanager = f"{clientinfo.get('client_name')}|1|2|{clientinfo.get('id_no')}|{clientinfo.get('id_end_date')}|#END#|" #资产管理人
        client_list.update({'investorprocode': investorprocode})
        client_list.update({'fundenddate': fundenddate})
        client_list.update({'assetmanager': assetmanager})
    client_list.update({'fundaccountnumber': TAACCOUNTID})
    client_list.update({'individualorinstitution': individualorinstitution})
    client_list.update({'investorname': investorname})
    client_list.update({'accountabbr': accountabbr})
    client_list.update({'certificatetype': certificatetype})
    client_list.update({'certificateno': certificateno})
    client_list.update({'certificatevalidityperiod': certificatevalidityperiod})
    client_list.update({'nationality': nationality})
    client_list.update({'address': address})
    client_list.update({'telno': telno})
    client_list.update({'emailaddress': emailaddress})
    client_list.update({'transactionaccountid': transactionaccountid})
    client_list.update({'taserialno': transactionaccountid})
    client_list.update({'managerange': managerange})
    client_list.update({'vocation': vocation})
    client_list.update({'regcapital': regcapital})
    client_list.update({'currencytype': currencytype})
    client_list.update({'orgno': orgno})
    client_list.update({'taxno': taxno})
    client_list.update({'instrepr': instrepr})
    client_list.update({'transactor': transactor})
    client_list.update({'controlholder': controlholder})
    client_list.update({'actualcontroller': actualcontroller})
    client_list.update({'beneowner': beneowner})
    client_list.update({'Transactionaccountnumber': transactionaccountid})


    #hsraw层，TA接口
    # TAACCOUNTID = str(randomInfo.get_random_number(12)) #基金账户
    c_custtype = '1'
    c_identitytype = '0'
    c_accostatus = 'N'
    c_requestno = TAACCOUNTID + str(randomInfo.get_random_number(8))
    c_outbusinflag = '101'
    ADDRESS = randomInfo.get_address().split(' ')[0] #通讯地址
    addr_zip = randomInfo.get_address().split(' ')
    POSTCODE = addr_zip[1]  #邮政编码
    TRD_ACCT = TAACCOUNTID + str(randomInfo.get_random_number(8)) # 交易账户
    bankinfo = randomInfo.get_bank().split(' ')
    INVESTOR_BANK_NAME = bankinfo[0]  # 开户银行名称
    c_bankno = bankinfo[1]  # 开户银行简称
    INVESTOR_BANK_ACCT = '622' + str(randomInfo.get_random_number(12))  # 银行卡号
    d_requestdate =  randomInfo.get_random_date(20230102,20240717) #申请日期
    d_cdate = d_requestdate
    d_date = d_requestdate
    d_regdate = d_requestdate
    agencyinfo = randomInfo.get_agency().split(' ')
    DISTRIBUTORCODE = agencyinfo[0] #销售商编号
    c_agencyname = agencyinfo[1]#销售商名称
    c_agencytype = agencyinfo[2]#销售商类型
    annualincome = randomInfo.get_random_number(6)
    livingcountry = '156'
    nationality = '156'
    Universaluniqueidentifiedcode = fake.uuid4()[:-4]
    client_list.update({'agencycode': DISTRIBUTORCODE})
    netcode = str(randomInfo.get_random_number(6))
    client_list.update({'netcode':netcode})
    client_list.update({'netname': f'网点{netcode}'})

    client_list.update({'Universaluniqueidentifiedcode': Universaluniqueidentifiedcode})
    certvaliddate = randomInfo.get_random_date(20240102,20401228)
    Serialnumber = randomInfo.get_random_number(9)
    client_list.update({'Serialnumber': Serialnumber})
    # client_list.update({'Bankcode': c_bankno})
    client_list.update({'nationality': nationality})
    client_list.update({'certvaliddate':certvaliddate})
    client_list.update({'livingcountry':livingcountry})
    client_list.update({'annualincome':annualincome})
    client_list.update({'TAACCOUNTID':TAACCOUNTID})
    client_list.update({'c_custtype':c_custtype})
    client_list.update({'c_identitytype':c_identitytype})
    client_list.update({'c_accostatus':c_accostatus})
    client_list.update({'c_requestno':c_requestno})
    client_list.update({'c_outbusinflag':c_outbusinflag})
    client_list.update({'ADDRESS':ADDRESS})
    client_list.update({'POSTCODE':POSTCODE})
    client_list.update({'TRD_ACCT':TRD_ACCT})
    client_list.update({'INVESTOR_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'OPEN_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'c_bankno':c_bankno})
    client_list.update({'INVESTOR_BANK_ACCT': INVESTOR_BANK_ACCT})
    client_list.update({'d_requestdate':d_requestdate})
    client_list.update({'d_cdate':d_cdate})
    client_list.update({'d_date':d_date})
    client_list.update({'d_regdate':d_regdate})
    client_list.update({'distributorcode':DISTRIBUTORCODE})
    client_list.update({'c_agencyname':c_agencyname})
    client_list.update({'c_agencytype':c_agencytype})
    # print(client_list)

    # client_list = {}
    # client_list.update(randomInfo.generate_info_raw())
    #hsraw层，BTA接口
    c_status = choice(['0','1','8','9']) #产品状态
    c_requestno = 'sq'+str(randomInfo.get_random_number(8))+str(randomInfo.get_random_number(8))
    c_outbusinflag = choice(['101','103'])
    c_sharetype = choice(['A','B'])
    c_othershare = c_sharetype
    c_businflag = choice(c_businflag_list)
    c_moneytype = '156'
    c_udid = str(randomInfo.get_random_number(24))#通用唯一识别码
    bankinfo = randomInfo.get_bank().split(' ')
    INVESTOR_BANK_NAME = bankinfo[0]  #开户银行名称
    c_bankno = bankinfo[1]  #开户银行简称
    INVESTOR_BANK_ACCT = '622' + str(randomInfo.get_random_number(12))  #银行卡号
    INVESTOR_BANK_OPENADDR = bankinfo[1]   #开户行地址
    # d_requestdate =  randomInfo.get_random_date(20230102,20240717) #申请日期
    d_requestdate = init_date
    d_cdate = d_requestdate
    d_date = d_requestdate
    d_regdate = d_requestdate
    d_datadate = d_requestdate
    c_cserialno = str(randomInfo.get_random_number(8))+str(randomInfo.get_random_number(8))
    f_balance = randomInfo.get_random_number(6)
    f_confirmbalance = f_balance
    f_netvalue = 1.25
    f_confirmshares = f_confirmbalance / f_netvalue
    c_bonustype = '1'
    agencyinfo = randomInfo.get_agency_ta().split(' ')
    DISTRIBUTORCODE = agencyinfo[0] #销售商编号
    BRANCHCODE = DISTRIBUTORCODE
    c_agencyname = agencyinfo[1]#销售商名称
    c_agencytype = agencyinfo[2]#销售商类型
    proinfo = randomInfo.get_pro().split(' ')
    c_fundcode = proinfo[0] #产品编号
    c_fundname = proinfo[1]#产品名称
    c_property = proinfo[2]#产品性质
    client_list.update({'INVESTOR_BANK_OPENADDR':INVESTOR_BANK_OPENADDR})
    client_list.update({'BRANCHCODE':BRANCHCODE})
    client_list.update({'c_status':c_status})
    client_list.update({'c_requestno':c_requestno})
    client_list.update({'c_outbusinflag':c_outbusinflag})
    client_list.update({'c_sharetype':c_sharetype})
    client_list.update({'c_othershare':c_othershare})
    client_list.update({'c_businflag':c_businflag})
    client_list.update({'c_moneytype':c_moneytype})
    client_list.update({'c_udid':c_udid})
    client_list.update({'INVESTOR_BANK_NAME':INVESTOR_BANK_NAME})
    client_list.update({'INVESTOR_BANK_ACCT':INVESTOR_BANK_ACCT})
    client_list.update({'c_bankno': c_bankno})
    client_list.update({'d_requestdate':d_requestdate})
    client_list.update({'d_cdate':d_cdate})
    client_list.update({'d_date':d_date})
    client_list.update({'d_regdate':d_regdate})
    client_list.update({'d_datadate':d_datadate})
    client_list.update({'c_cserialno':c_cserialno})
    client_list.update({'f_balance':f_balance})
    client_list.update({'f_confirmbalance':f_confirmbalance})
    client_list.update({'f_netvalue':f_netvalue})
    client_list.update({'f_confirmshares':f_confirmshares})
    client_list.update({'c_bonustype':c_bonustype})
    client_list.update({'DISTRIBUTORCODE':DISTRIBUTORCODE})
    client_list.update({'c_agencyname':c_agencyname})
    client_list.update({'c_agencytype':c_agencytype})
    client_list.update({'c_fundcode':c_fundcode})
    client_list.update({'FundCode':c_fundcode})
    client_list.update({'c_fundname': c_fundname})
    client_list.update({'c_property': c_property})
    # print(client_list)

    defdividendmethod = choice(['0','1'])
    client_list.update({'opbankofinvestorinclearing': INVESTOR_BANK_NAME})
    client_list.update({'acctnoofinvestorinclearing': INVESTOR_BANK_ACCT})
    client_list.update({'acctnameofinvestorinclearing': investorname})
    client_list.update({'defdividendmethod': defdividendmethod})
    client_list.update({'c_tano': c_tano})
    sql_list_copy = {k.lower(): v for k, v in client_list.items()}
    return sql_list_copy

def sql_source_list():
    listInfo = [1,2,3,4,5,6,7,8,9,10,11,12]
    key = get_sql_key(table='taaml_n_acconet_fund')
    value = get_sql(table='taaml_n_acconet_fund')
    listInfo[0]={'key':key,'value':value}
    key = get_sql_key(table='taaml_n_accorequest_fund')
    value = get_sql(table='taaml_n_accorequest_fund')
    listInfo[1]={'key':key,'value':value}
    key = get_sql_key(table='taaml_n_confirm_fund')
    value = get_sql(table='taaml_n_confirm_fund')
    listInfo[2]={'key':key,'value':value}
    key = get_sql_key(table='taaml_n_crsrequest_fund')
    value = get_sql(table='taaml_n_crsrequest_fund')
    listInfo[3] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_customerinfo_fund')
    value = get_sql(table='taaml_n_customerinfo_fund')
    listInfo[4] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_dividenddetail_fund')
    value = get_sql(table='taaml_n_dividenddetail_fund')
    listInfo[5] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_fundarlimit_fund')
    value = get_sql(table='taaml_n_fundarlimit_fund')
    listInfo[6] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_income_fund')
    value = get_sql(table='taaml_n_income_fund')
    listInfo[7] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_netinfo_fund')
    value = get_sql(table='taaml_n_netinfo_fund')
    listInfo[8] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_request_fund')
    value = get_sql(table='taaml_n_request_fund')
    listInfo[9] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_sharecurrents_fund')
    value = get_sql(table='taaml_n_sharecurrents_fund')
    listInfo[10] = {'key': key, 'value': value}
    key = get_sql_key(table='taaml_n_staticshares_fund')
    value = get_sql(table='taaml_n_staticshares_fund')
    listInfo[11] = {'key': key, 'value': value}
    return listInfo



if __name__ == '__main__':
    str = fake.company()
    print(str[:-4])